package com.zzc.service;

import com.google.gson.Gson;
import org.apache.struts2.ServletActionContext;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/4/13 0013.
 */
public class BaseService{
    public static void printAll(Object object) {
        HttpServletResponse response = ServletActionContext.getResponse();
        try {
            ServletOutputStream out = response.getOutputStream();
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-type", "text/html;charset=UTF-8");
            response.setContentType("text/html;charset=UTF-8");
            String string_list_wares=new Gson().toJson(object);
            byte[] bytes_list_wares=string_list_wares.getBytes("UTF-8");
            out.write(bytes_list_wares);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void printAll_json(Object object) {
        HttpServletResponse response = ServletActionContext.getResponse();
        try {
            ServletOutputStream out = response.getOutputStream();
            response.setContentType("application/json;charset=utf-8");
            String string_list_wares=new Gson().toJson(object);
            byte[] bytes_list_wares=string_list_wares.getBytes("UTF-8");
            out.write(bytes_list_wares);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void printAll_string(String object) {
        HttpServletResponse response = ServletActionContext.getResponse();
        try {
            ServletOutputStream out = response.getOutputStream();
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-type", "text/html;charset=UTF-8");
            response.setContentType("text/html;charset=UTF-8");
            byte[] bytes_list_wares=object.getBytes("UTF-8");
            out.write(bytes_list_wares);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
